<?php
    include('checkAdminAccess.php');
    $iniVars = parse_ini_file('../../config.ini',TRUE);
    include('../classes/adodb5/adodb.inc.php');
    include('../function/db.func.php');
    
    if(isset($_POST['cMapId']))
    {
        $cMapId = $_POST['cMapId'];
        $sql = "SELECT cmap_path FROM contact_map WHERE cmap_id=$cMapId";
        $resultX = $db->Execute($sql);
        $sql = "DELETE FROM contact_map WHERE cmap_id=$cMapId";
        $result = $db->Execute($sql);
        if($result){
            if(file_exists($iniVars['Locations']['sitepath'].'images/cmap/'.$resultX->fields['cmap_path']) AND $resultX->fields['cmap_path']!=''){
                unlink($iniVars['Locations']['sitepath'].'images/cmap/'.$resultX->fields['cmap_path']);
            }
            echo 'success';
        }
        else
        {
            echo 'ไม่สามารถลบข้อมูลได้ กรุณาลองใหม่อีกครั้งภายหลัง';
        }
    }
    else
    {
        echo 'ข้อมูลไม่ถูกต้อง';
    }
?>